<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="modelList" row-key="order" :tree-props="{children: 'subCandidateValues', hasChildren: 'hasChildren'}">>
      <el-table-column label="模型编号" prop="id" />
      <el-table-column label="模型名称" prop="name" :show-overflow-tooltip="true" />
    </el-table>

  </div>
</template>

<script>
import { listBase } from "@/api/ai/model";

export default {
  name: "model",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 模型表格数据
      modelList: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询模型列表 */
    getList() {
      this.loading = true;
      listBase({}).then(response => {
        let modelList = [];
        let rows = response.rows || [];
        rows.forEach((el, i) => {
          let obj = Object.assign(el, { order: i + 1 });
          if (el.subCandidateValues && el.subCandidateValues.length > 0) {
            let arr = [];
            el.subCandidateValues.forEach((subEl, j) => {
              arr.push(Object.assign(subEl, { order: i + 1 + '' + j }))
            })
            obj['subCandidateValues'] = arr;
          }
          modelList.push(obj);
        })
        this.modelList = modelList;
        this.loading = false;
      }
      );
    },
  }
};
</script>